import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";

export const Login = () => import("@/views/login.vue");
export const Home = () => import("@/views/home.vue");
export const Index = () => import("@/views/index.vue");

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/login",
    component: Login,
  },
  {
    path: "/",
    component: Index,
  },
  {
    path: "/home",
    component: Home,
  },
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes as RouteRecordRaw[],
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/login" });
}

export default router;